import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:xvideos/assets_tool/images.dart';
import 'package:xvideos/hj_model/video_model.dart';
import 'package:xvideos/hj_page/community_business/post_detail_page/post_detail_page.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';
import 'package:xvideos/tools_base/widget/net_image_widget.dart';

class GameItem extends StatelessWidget {
  final VideoModel model;
  final List<VideoModel>? models; //

  const GameItem(this.model, {super.key, this.models});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => Get.toNamed(PostDetailPage.routeName, arguments: PostDetailPageArgument(id: model.id, models: models)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Expanded(
            child: Stack(
              alignment: Alignment.bottomCenter,
              children: [
                NetworkImageLoader(
                  imageUrl: model.cover ?? '',
                  borderRadius: 9,
                  width: double.infinity,
                  height: double.infinity,
                ),
                Container(
                  padding: EdgeInsets.only(left: 8.w, right: 8.w, bottom: 6.h, top: 4.h),
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                      colors: [Colors.transparent, Colors.black.withOpacity(.6)],
                      begin: Alignment.topCenter,
                      end: Alignment.bottomCenter,
                    ),
                  ),
                  child: Row(
                    children: [
                      Text(
                        '${model.pageViewCount.humanizeFormat} 浏览',
                        style: TextStyle(color: Colors.white, fontSize: 14.sp),
                      ),
                      Spacer(),
                      Text(
                        '${model.purchaseCount.humanizeFormat}解锁',
                        style: TextStyle(color: Colors.white, fontSize: 14.sp),
                      )
                    ],
                  ),
                ),
                Positioned(
                  right: 0,
                  top: 0,
                  child: _buildPriceItem(),
                ),
              ],
            ),
          ),
          Container(
            height: 66.h,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                4.h.sizeBoxH,
                Expanded(
                  child: Text(
                    model.title ?? '',
                    maxLines: 2,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(color: Colors.white, fontSize: 14.sp),
                  ),
                ),
                Text(
                  model.tags?.map((e) => e.name ?? '').toList().join('.') ?? '',
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(color: Colors.white.withOpacity(.6), fontSize: 14.sp),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildPriceItem() {
    if (model.permission == 2) {
      return Container(
        padding: EdgeInsets.symmetric(horizontal: 6, vertical: 2),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.only(
            topRight: Radius.circular(8),
            bottomLeft: Radius.circular(8),
          ),
          gradient: LinearGradient(
            colors: [
              Color(0xffADFCAC),
              Color(0xff5CEF97),
            ],
          ),
        ),
        child: Text(
          "免费",
          style: TextStyle(
            color: Colors.black,
            fontSize: 10,
          ),
        ),
      );
    }
    if (model.permission == 1) {
      return Container(
        padding: EdgeInsets.symmetric(horizontal: 6, vertical: 3),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.only(
            topRight: Radius.circular(8),
            bottomLeft: Radius.circular(8),
          ),
          gradient: LinearGradient(
            colors: [
              Color(0xffDB361F),
              Color(0xffDB361F),
            ],
          ),
        ),
        child: Image.asset("coin.webp".commonImgPath, width: 14, height: 14),
      );
    }
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 6, vertical: 2),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.only(
          topRight: Radius.circular(8),
          bottomLeft: Radius.circular(8),
        ),
        gradient: LinearGradient(
          colors: [
            Color(0xffF6CBB8),
            Color(0xffEEB4AA),
          ],
        ),
      ),
      child: Text(
        "VIP",
        style: TextStyle(
          color: Colors.black,
          fontSize: 12,
        ),
      ),
    );
  }
}
